package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.domain.entity.SysDept;
import com.fas.common.core.domain.model.LoginUser;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasMiniatureStation;
import com.fas.system.service.IFasMiniatureStationService;
import com.fas.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 微型消防站信息Controller
 *
 * @date 2022-06-28
 */
@Api(tags = "微型消防站信息")
@RestController
@RequestMapping("/system/miniaturestation")
public class FasMiniatureStationController extends BaseController {

    @Resource
    private IFasMiniatureStationService fasMiniatureStationService;
    @Resource
    private ISysDeptService deptService;

    @ApiOperation(value = "总公司查询微型消防站信息")
//    @PreAuthorize("@ss.hasPermi('system:equipment:ceshi')")
    @GetMapping("/findAll")
    public TableDataInfo findAllEquipment(FasMiniatureStation fasMiniatureStation){
        System.out.println("输入的参数："+ fasMiniatureStation.toString());
        LoginUser user = SecurityUtils.getLoginUser();
        SysDept sysDept = deptService.selectDeptById(user.getDeptId());
//        DeptType :  0:总部 1:渠道商 2:维保单位
        if("0".equals(sysDept.getDeptType())){
            startPage();
            List<FasMiniatureStation> fasMiniatureStationList = fasMiniatureStationService.findAllEquipment(fasMiniatureStation);
            return getDataTable(fasMiniatureStationList);
        }else if("2".equals(sysDept.getDeptType())){
            fasMiniatureStation.setDeptId(user.getDeptId());
            List<FasMiniatureStation> allEquipment = fasMiniatureStationService.findLikeEngineer(fasMiniatureStation);
            return getDataTable(allEquipment);
        }
        return null;
    }

    @ApiOperation(value = "新增微型消防站")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasMiniatureStation fasMiniatureStation){
        LoginUser user = SecurityUtils.getLoginUser();
        fasMiniatureStation.setDeptId(user.getDeptId());
        return AjaxResult.success(fasMiniatureStationService.insertFasMiniatureStation(fasMiniatureStation));
    }

    @ApiOperation(value = "修改微型消防站")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasMiniatureStation fasMiniatureStation){
        return AjaxResult.success(fasMiniatureStationService.updateFasMiniatureStation(fasMiniatureStation));
    }

    @ApiOperation(value = "删除微型消防站")
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable("ids")Integer[] ids){
        return AjaxResult.success(fasMiniatureStationService.deleteFasMiniatureStation(ids));
    }

    @ApiOperation(value = "查询微型消防站详细")
    @GetMapping("/findById/{id}")
    public AjaxResult findById(@PathVariable("id")Integer id){
        LoginUser user = SecurityUtils.getLoginUser();
        Long deptId = user.getDeptId();
        return AjaxResult.success(fasMiniatureStationService.findById(id,deptId));
    }

}
